//
//  ShowVC.m
//  Buiom_7.0
//
//  Created by lanou3g on 15/10/28.
//  Copyright © 2015年 triffe. All rights reserved.
//

#import "ShowVC.h"
#import "ShouCell.h"
#import "PlayVC.h"

@interface ShowVC ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *nameArray;

@end

@implementation ShowVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    self.title = @"八部锻炼";
    self.navigationController.navigationBar.translucent = NO; //导航条下为原点
    //self.navigationController.navigationBarHidden = YES;  //隐藏导航条
    [self setData];
    [self addSubViews];
    
    //UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithTitle:@"<" style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    // 添加左边返回按钮.
    
//    UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"houtuiyibu.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:(UIBarButtonItemStylePlain) target:self action:@selector(backAction)];
//    self.navigationItem.leftBarButtonItem = left;
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(actionLeftBarButton)];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
}
- (void)actionLeftBarButton
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

// 加载数据
- (void)setData{
    _nameArray = @[@"腿部",@"臀部",@"腹部",@"肩部",@"胸部",@"背部",@"手臂",@"拉伸"];
}
// 创建视图
- (void)addSubViews{
    
   
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 2;
    layout.minimumInteritemSpacing = 2;
    layout.itemSize = CGSizeMake(kWidth/2 - 4, kHeight/3 - 8);
    layout.sectionInset = UIEdgeInsetsMake(2, 3, 3, 3);
    //layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;//左右滑动
   
    //初始化集合视图
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 64) collectionViewLayout:layout];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
   
    _collectionView.bounces = NO; //禁止反弹
    _collectionView.showsVerticalScrollIndicator = NO; //不显示滚动条
    _collectionView.backgroundColor = [UIColor darkGrayColor];
    
    [self.view addSubview:_collectionView];
    
    //注册要用的cell
    [_collectionView registerClass:[ShouCell class] forCellWithReuseIdentifier:@"cell"];

}

//协议要实现的方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 8;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
   
    ShouCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.label.text = self.nameArray[indexPath.row];
    cell.label.textColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor lightGrayColor];
    return cell;
    
}

// 跳到下个界面
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
 
    NSArray *urlArray = @[kLeg,kButtock,kAbdomen,kShoulders,kBreast,kBack,kArm,kLigament];
    //按照indexPath.row 来分配
    PlayVC *playVC = [[PlayVC alloc] init];
    playVC.url = urlArray[indexPath.row];

    [self.navigationController pushViewController:playVC animated:YES];
    NSLog(@"0000");
    
}
















@end
